import copy
def GF28(p):
   class Polynomial():
      def __init__(self, n):
         self.n = n
         self.field = GF28
 
      def __add__(self, other): return self.mod(self.xor(self.n, other.n))
      def __sub__(self, other): return self.mod(self.xor(self.n, other.n))
      def __mul__(self, other): return self.mod(self.mul(self.n, other.n))
      def __div__(self, other): return self.mod(self.mul(self.n, other.inverse()))
 
      def inverse(self):
         return 0
 
      def xor(self, a, b):
          self.padding(a, b)
          ret = []
          l = len(a)
          for i in range(0,l):
              if(a[i]==b[i]):
                  ret.append(0)
              else:
                  ret.append(1)
                  
          for i in range(0,l):
              if(ret[0]==0):
                  ret.remove(0)
              else:
                  break;
                  
          #print 'in',a, b,'xor ret',ret              
          return ret
          
      def padding(self, a, b):
          #l = max(len(self.n), len(b))
          if len(a)==len(b):
              return
              
          if len(a)>len(b):
              ll = len(a) - len(b)
              for i in range(0,ll):
                  b.insert(0,0)
          else:
              ll = len(b) - len(a)
              for i in range(0,ll):
                  a.insert(0,0)
      
      def mul(self, a, b):
          ret = [0]
          x = []
          for i in range(0,len(b)):
              if(b[i]==1):
                  zeronum=len(b)-1-i
                  #print 'zero num',zeronum
              else:
                  continue
              x = copy.deepcopy(a)
              for j in range(0,zeronum):
                  x.append(0)
              ret =  self.xor(ret, x)
              #print 'x in a', x
              #print 'mul xor ret',ret          
          return ret

      def mod(self, x):
          if(len(x)<len(self.p)):
              return x                    
          temp=[]
          modlen = 0
          startidx = 0
          endidx = len(self.p)
          if len(x) >= len(self.p):              
              while endidx<=len(x):    
                  for i in range(startidx, endidx):
                      temp.append(x[i])
                  #print temp
                  temp = self.xor(temp, self.p)
                  modlen = len(temp)
                  startidx = endidx
                  endidx += (len(p)-modlen)                  
                  #print temp
                  #print modlen,startidx,endidx
                  #break  
          if(len(x)-startidx > 0):
              for i in range(startidx, len(x)):
                  temp.append(x[i])
          return temp
         
   Polynomial.p = p
   Polynomial.__name__ = 'irreducible polynomial is %s' % (p)
   return Polynomial

#test cases
ploy = [1,1,0,1,1]
gf = GF28(ploy)
print gf
ploy1 = [1,1,0,0,1]
ploy2 = [1,1,1]
#print ploy1
#print ploy2
print gf(ploy1)*gf(ploy2)

#print gf(ploy2).mod(ploy2)
